package com.bric.cacheFile;

import java.io.File;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ThreadPoolExecutor;

import com.bric.util.StaticStr;
import com.bric.util.ThreadPools;

/**
 * 调度线程池进行缓存文件往ftp分发的类
 * @author Administrator
 *
 */
public class CacheFileScheduled extends Thread{
	public static Queue<File> cacheFilequeue=new ConcurrentLinkedQueue<File>();
	@Override
	public void run() {
		File file=new File(StaticStr.localFilePath+StaticStr.cacheFilePath);
//		File file=new File("D:/fagaiwei");
		getFile(file);
		ThreadPoolExecutor excuter=ThreadPools.getSingleton().getTheadPools();
		Cache2Ftp ftp=new Cache2Ftp();
		Thread t1=new Thread(ftp);
		Thread t2=new Thread(ftp);
		Thread t3=new Thread(ftp);
		Thread t4=new Thread(ftp);
		excuter.execute(t1);
		excuter.execute(t2);
		excuter.execute(t3);
		excuter.execute(t4);
	}
	void getFile(File file){
		if(file.exists()&&file.isDirectory()){
			File[] files=file.listFiles();
			for(File f:files){
				if(f.isDirectory()){
					getFile(f);
				}else{
					cacheFilequeue.add(f);
				}
			}
		}
	}
	public static void main(String[] args) {
		CacheFileScheduled sch=new CacheFileScheduled();
		Thread t1=new Thread(sch);
		t1.start();
	}
}
